﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BF.Common
{
    /// <summary>
    /// 分页基类
    /// </summary>
    public abstract class Pager<T>
    {
        /// <summary>
        /// 返回记录集数
        /// </summary>
        protected int PageRecordCount { get; set; }
        /// <summary>
        /// 当前第几页
        /// </summary>
        protected int PageCurrentIndex { get; set; }
        /// <summary>
        /// 总页数
        /// </summary>
        public int PageAllCount { get; set; }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="PageRecordCount"></param>
        /// <param name="PageCurrentIndex"></param>
        public Pager(int PageRecordCount, int PageCurrentIndex)
        {
            this.PageRecordCount = PageRecordCount;
            this.PageCurrentIndex = PageCurrentIndex;

        }
        /// <summary>
        /// 返回经过分页的记录集
        /// </summary>
        /// <param name="PageRecordCount">返回记录集数</param>
        /// <param name="PageCurrentIndex">当前第几页</param>
        /// <param name="PageAllCount">总页数</param>
        /// <returns></returns>
        public abstract List<T> return_List_pager(IQueryable<T> IQueryableList);
    }
    /// <summary>
    /// 适用于AspNetPager分页的子类
    /// </summary>
    public class AspNetPager<T> : Pager<T>
    {
        public AspNetPager(int PageRecordCount, int PageCurrentIndex)
            : base(PageRecordCount, PageCurrentIndex)
        { }
        public override List<T> return_List_pager(IQueryable<T> IQueryableList)
        {
            return IQueryableList.Skip(PageRecordCount * (PageCurrentIndex - 1)).Take(PageRecordCount).ToList();
        }
    }
    /// <summary>
    /// 适用于ExtToolPager分页的子类
    /// </summary>
    public class ExtToolPager<T> : Pager<T>
    {
        public ExtToolPager(int PageRecordCount, int PageCurrentIndex)
            : base(PageRecordCount, PageCurrentIndex)
        { }
        public override List<T> return_List_pager(IQueryable<T> IQueryableList)
        {
            return IQueryableList.Skip(PageCurrentIndex).Take(PageRecordCount).ToList();
        }
    }
}
